package com.ks.sgms.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.ks.sgms.entity.MClass;
import com.ks.sgms.entity.Student;
import com.ks.sgms.util.DbHelper;

public class ClassDao {
	public MClass selectClassByName(String class_name) {
		Connection conn = DbHelper.getConnection();
		String sql = "select * from class where class_name = ?"; 
		MClass c = new MClass();
		try {
			PreparedStatement pst = conn.prepareStatement(sql);
			pst.setString(1, class_name);
			ResultSet rst = pst.executeQuery();
			if (rst.next()) {
				c.class_id = rst.getString("class_id");
				c.class_name = rst.getString("class_name");
				c.major_id = rst.getString("major_id");
			}
			pst.close();
			rst.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		System.out.println(c);
		return c; 
	}
}
